from flask import Blueprint, render_template, request, jsonify
from decorators import check_login
from bson_document import Members

bp = Blueprint('account', __name__, url_prefix='/account')


@bp.route('/')
@check_login
def index():
    print(request.args)
    return render_template("account/index.html")


@bp.route('/member/save')
def member_save():
    member = Members(name='hello', email='844826411@qq.com', sex=True)
    member.save()
    return "it is ok."


@bp.route('/member/list')
def member_list():
    all_members = Members.objects
    # all_members = Members.objects[:10]
    # all_members = Members.objects[10:20]
    for m in all_members:
        print(m.name)
    return jsonify(all_members)


@bp.route('/member/query')
def member_query():
    all_members = Members.objects(name=request.args.get('name'))
    for m in all_members:
        print(m.name)
    return jsonify(all_members)
